#include"BlockQueue.hpp"

void *Product(void *arg)
{
  auto bq=(BlockQueue<int>*)arg;
  while(true)
  {
    sleep(1);
    int data=rand()%100+1;
    bq->push(data);//生产数据
    cout<<"生产数据"<<data<<endl;
  }
}
void *Customer(void *arg)
{
  auto bq=(BlockQueue<int>*)arg;
  while(true)
  {
    sleep(3);
    int data=0;
    bq->pop(data);
    cout<<"消费数据"<<data<<endl;
  }
  
}

int main()
{
  //创建线程
  pthread_t cust,pro;
  BlockQueue<int>* bq=new BlockQueue<int>();

  pthread_create(&pro,nullptr,Product,(void*)bq);
  pthread_create(&cust,nullptr,Customer,(void*)bq);


  pthread_join(cust,nullptr);
  pthread_join(pro,nullptr);
  return 0;
}
